/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import com.openbrew.openbrewrf.views.POSBeerView;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "posProducts")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "POSProducts.findAllASC", query = "SELECT p FROM POSProducts p ORDER BY p.productDescription ASC"),
    @NamedQuery(name = "POSProducts.findAllDSC", query = "SELECT p FROM POSProducts p ORDER BY p.productDescription DESC"),
    @NamedQuery(name = "POSProducts.getTapped", query = "SELECT p FROM POSProducts p WHERE p.productOnTap = 'true' ORDER BY p.productDescription ASC")})
public class POSProducts implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "productID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 250)
    @Column(name = "description")
    private String productDescription;
    @Basic(optional = false)
    @NotNull
    @Column(name = "onTap")
    private boolean productOnTap;
    @JoinColumn(name = "beer", referencedColumnName = "BId", nullable=true)
    @ManyToOne(optional = true)
    private POSBeerView productBeer;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="posJTServingTypes",
        joinColumns={ @JoinColumn(name="productID", referencedColumnName="productID")},
        inverseJoinColumns={ @JoinColumn(name="servingTypeID", referencedColumnName="servingTypeID", unique=true)}
    )
    private List<POSProductServingType> servingTypeCollection;

    public POSProducts() {
    }

    public POSProducts(Integer id) {
        this.id = id;
    }

    public POSProducts(Integer id, String productDescription, boolean productOnTap) {
        this.id = id;
        this.productDescription = productDescription;
        this.productOnTap = productOnTap;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getProductDescription() {
        return productDescription;
    }

    public void setProductDescription(String productDescription) {
        this.productDescription = productDescription;
    }

    public boolean isProductOnTap() {
        return productOnTap;
    }

    public void setProductOnTap(boolean productOnTap) {
        this.productOnTap = productOnTap;
    }

    public POSBeerView getProductBeer() {
        return productBeer;
    }

    public void setProductBeer(POSBeerView productBeer) {
        if(productBeer != null && productBeer.getbId()!=null){
            this.productBeer = productBeer;
        }
    }

    public List<POSProductServingType> getServingTypeCollection() {
        return servingTypeCollection;
    }

    public void setServingTypeCollection(List<POSProductServingType> servingTypeCollection) {
        this.servingTypeCollection = servingTypeCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSProducts)) {
            return false;
        }
        POSProducts other = (POSProducts) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.posproducts[ id=" + id + " ]";
    }
}
